package com.meishij.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jash.myutils.utils.ImageUtils;
import com.meishij.R;
import com.meishij.entry.RecommendEntry;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/14.
 * <p>
 * ,.
 * ,_> `.   ,';
 * ,-`'      `'   '`'._
 * ,,-) ---._   |   .---''`-),.
 * ,'      `.  \  ;  /   _,'     `,
 * ,--' ____       \   '  ,'    ___  `-,
 * _>   /--. `-.              .-'.--\   \__
 * '-,  (    `.  `.,`~ \~'-. ,' ,'    )    _\
 * _<    \     \ ,'  ') )   `. /     /    <,.
 * ,-'   _,  \    ,'    ( /      `.    /        `-,
 * `-.,-'     `.,'       `         `.,'  `\    ,-'
 * ,'       _  /   ,,,      ,,,     \     `-. `-._
 * /-,     ,'  ;   ' _ \    / _ `     ; `.     `(`-\
 * /-,        ;    (o)      (o)      ;          `'`,
 * ,~-'  ,-'    \     '        `      /     \      <_
 * /-. ,'        \                   /       \     ,-'
 * '`,     ,'   `-/             \-' `.      `-. <
 * /_    /      /   (_     _)   \    \          `,
 * `-._;  ,' |  .::.`-.-' :..  |       `-.    _\
 * _/       \  `:: ,^. :.:' / `.        \,-'
 * '`.   ,-'  /`-..-'-.-`-..-'\            `-.
 * >_ /     ;  (\/( ' )\/)  ;     `-.    _<
 * ,-'      `.  \`-^^^-'/  ,'        \ _<
 * `-,  ,'   `. `"""""' ,'   `-.   <`'
 * ')        `._.,,_.'        \ ,-'
 * '._        '`'`'   \       <
 * >   ,'       ,   `-.   <`'
 * `,/          \      ,-`
 * `,   ,' |   /     /
 * '; /   ;        (
 * _)|   `       (
 * `')         .-'
 * <_   \   /    hjw
 * \   /\(
 * `;/  `
 */

public class RecommendTopViewPagerAdapter extends PagerAdapter {
    private List<RecommendEntry.ObjBean.Top3Bean> top3;

    public RecommendTopViewPagerAdapter(List<RecommendEntry.ObjBean.Top3Bean> top3) {
        this.top3 = new ArrayList<>();
        RecommendEntry.ObjBean.Top3Bean first = top3.get(0);
        RecommendEntry.ObjBean.Top3Bean last = top3.get(top3.size()-1);
        this.top3.addAll(top3);
        this.top3.add(0,last);
        this.top3.add(first);
    }

    @Override
    public int getCount() {
        return top3 == null ? 0 : top3.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(container.getContext());
        imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        ImageUtils.loadImage(imageView, top3.get(position).getPhoto(), R.mipmap.ic_launcher);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(((ImageView) object));
    }
}
